package com.example.demo.mapper;

import com.example.demo.entity.InstrumentCollection;
import com.example.demo.entity.TheoryKnowledgeCollection;
import org.apache.ibatis.annotations.*;

import java.util.List;
@Mapper
public interface TheoryKnowledgeCollectionMapper {

    // 添加收藏
    @Insert("INSERT INTO theory_knowledge_collection_tb (user_id, theory_knowledge_id, collection_date) " +
            "VALUES (#{user_id}, #{theory_knowledge_id}, #{collection_date})")
    int addCollection(TheoryKnowledgeCollection theoryKnowledgeCollection);

    // 删除收藏
    @Delete("DELETE FROM theory_knowledge_collection_tb WHERE user_id = #{user_id} AND theory_knowledge_id = #{theory_knowledge_id}")
    int deleteCollection(@Param("user_id") Integer userId, @Param("theory_knowledge_id") Integer theoryKnowledgeId);

    // 查询用户收藏的所有乐器
    @Select("SELECT c.*, i.name AS name, i.type AS type, i.cover_image AS image " +
            "FROM theory_knowledge_collection_tb c " +
            "JOIN theory_knowledge_tb i ON c.theory_knowledge_id = i.theory_knowledge_id " +
            "WHERE c.user_id = #{user_id}")
    List<TheoryKnowledgeCollection> getCollectionsByUserId(@Param("user_id") Integer userId);

    // 检查用户是否收藏某个乐器
    @Select("SELECT COUNT(*) FROM theory_knowledge_collection_tb WHERE user_id = #{user_id} AND theory_knowledge_id = #{theory_knowledge_id}")
    int checkIfCollected(@Param("user_id") Integer userId, @Param("theory_knowledge_id") Integer theoryKnowledgeId);

    //点击量(点击笔记浏览量)
    @Update("UPDATE theory_knowledge_tb SET view_count = view_count + 1 WHERE theory_knowledge_id = #{theory_knowledge_id}")
    Integer clickViewCount(@Param("theory_knowledge_id") Integer theory_knowledge_id);


}
